package com.hy.controller;

import com.hy.bean.PageBean;
import com.hy.bean.RespBean;
import com.hy.bean.SysDept;
import com.hy.dao.SysDeptDao;
import com.hy.dto.DeptDto;
import com.hy.service.impl.DeptServiceimpl;

import java.util.List;
import java.util.Map;

/**
 *
 *
 * @Description: 部门管理
 * @Author: zhangzhengwei2006
 * @Date: 2024-02-01 1:07
 *
 *
 */
public class DeptController {

    private DeptServiceimpl deptServiceimpl = new DeptServiceimpl();
    private SysDeptDao deptDao = new SysDeptDao();

    // 查询全部
    public List<Map<String, Object>> select() throws Exception {
        return deptServiceimpl.list();
    }

    public List<SysDept> selectAllDeptList() throws Exception{
        return deptDao.selectAllDeptList();
    }

    // 根据id查询
    public PageBean<SysDept> selectById(Integer id) throws Exception {
        PageBean<SysDept> pageBean = new PageBean<>();
        pageBean.setData(deptDao.selectLeelById(id));
        return pageBean;
    }

    // 查询重复
    public boolean selectName(String name) throws Exception {
        return deptDao.selectByName(name);
    }

    // 添加部门
    public RespBean save(String name, Integer seq, String remark, String status, Integer parent_id, String operator, String operate_ip) throws Exception {
        SysDept dept = new SysDept(null,name,"0",seq,remark,status,parent_id,operator,null,operate_ip,null);
        return deptServiceimpl.save(dept);
    }

    // 修改部门 TODO
    public Boolean updateById(Integer id, String name, Integer seq, String remark, String status, Integer parent_id, String operator, String operate_ip) throws Exception {
        DeptDto dept = new DeptDto(id,name,parent_id,seq,remark,operator,operate_ip);
        return deptServiceimpl.updateDept(dept);
    }

    //删除
    public RespBean delete(Integer id) throws Exception {
        return deptServiceimpl.del(id);
    }

}
